<?php
/**
 * @name /lib/public/HTMLControls/Combobox.php
 * @author Michael Foss <webdesign@matatechconsulting.com>
 * @version 2008.09.06
 *
 * Checkbox class library.
 */

ReqLib('/lib/public/HTMLControls/HTMLControl.php');

/**
 * Checkbox class.
 *
 */
class Checkbox extends HTMLControl {
  /**
   * The value for the control.
   *
   * @var string
   */
  var $Value;
  var $Text;
  var $Checked;
  var $OnClick;
  var $ContainerStyle;

  /**
   * Constructor.
   *
   * @param string $Id
   * @param string $Text
   * @param string $Value
   */
  function Checkbox($Id, $Text = '', $Value = '') {
    $this->HTMLControl($Id);
    $this->Text = $Text;
    $this->Value = '';
    $this->Checked = false;
    $this->OnClick = '';
    $this->ContainerStyle = '';
  }

  /**
   * Gets the value currently assigned to the control.
   *
   * @return string
   */
  function GetValue() {
    return $this->Value;
  }

  /**
   * Sets the value of the control.
   *
   * @param string $Value
   */
  function SetValue($Value = '') {
    $this->Value = $Value;
  }

  function IsChecked() {
    return $this->Checked;
  }
  function Check() {
    $this->Checked = true;
  }
  function Uncheck() {
    $this->Checked = false;
  }
  function Toggle() {
    $this->Checked = !$this->Checked;
  }
  function Display() {
    if (!$this->Id)
      return false;
    if ($this->ContainerStyle)
      print('<div class="CheckboxContainer" style="' . htmlspecialchars($this->ContainerStyle) . '">');
    else
      print('<div class="CheckboxContainer">');
    print('<input type="checkbox" id="' . htmlspecialchars($this->Id) . '" name="' . htmlspecialchars($this->Id) . '"' . ($this->Checked ? ' checked="checked"' : '') . ($this->Value ? ' value="' . htmlspecialchars($this->Value) . '"' : '') . ($this->OnClick ? ' onclick="' . str_replace('"', '\"', $this->OnClick) . '"' : '') . ' />');
    print('<label for="' . htmlspecialchars($this->Id) . '">' . htmlspecialchars($this->Text) . '</label>');
    print('</div>');
    return true;
  }
}